class ListNode {
    int val;
    ListNode next;
    ListNode head;
    ListNode() {
    }
    ListNode(int val) {
        this.val = val;
    }
    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
    public void addLast(int val){
        ListNode cur = this;
        if (this == null){
            cur.val = val;
            this.head = cur;
        }
        while (cur != null){

        }
    }
    public void display(){
        ListNode cur = this;
        while (cur != null){
            System.out.println(cur.val+" ");
            cur = cur.next;
        }
    }
}
public class Test {

    public ListNode removeElements(ListNode head, int val) {
        if (head == null) return head;
        ListNode cur = head;
        while (cur != null && cur.next != null){
            if (cur.next.val == val){
                cur.next = cur.next.next;
            } else {
                cur = cur.next;
            }
        }
        if (head.val == val){
            head = head.next;
        }
        return head;
    }

    public static void main(String[] args) {
        ListNode list1 = new ListNode();

    }
}

/*
class Solution {
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        if (list1 == null) return list2;
        if (list2 == null) return list1;

        ListNode head = new ListNode(-1);
        ListNode cur = head;
        while (list1 != null && list2 != null){
            if (list1.val < list2.val){
                cur.next = list1;
                list1 = list1.next;
                cur = cur.next;
            } else {
                cur.next = list2;
                list2 = list2.next;
                cur = cur.next;
            }
        }
        if (list1 != null) {
            cur.next = list1;
        }
        if (list2 != null) {
            cur.next = list2;
        }
        return head.next;
    }
}*/